package account

import (
	"encoding/json"
	"longmen/server/pkg/db/mysql/db_main"
	"longmen/server/pkg/db/mysql/models/models_main"
	"sync"

	"go.uber.org/zap"
)

type Account struct {
	logger *zap.SugaredLogger
}

var instance *Account
var once sync.Once

func New(log *zap.SugaredLogger) *Account {
	once.Do(func() {
		instance = &Account{
			logger: log,
		}
	})
	return instance
}

// UserLogHandler 用户日志
func (a *Account) UserLogHandler(msg []byte) bool {
	var user_log models_main.UserLog
	err := json.Unmarshal(msg, &user_log)
	if err != nil {
		a.logger.Errorf("SubMessage GiftLogHandler err [%v]", err)

	}
	logId := 0
	logId, err = db_main.InsertLogDB(&user_log)
	if err != nil || logId == 0 {
		return false
	}
	return true
}
